package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.commons.ResponseResult;
import cn.kgc.ssm.entity.LogInfo;
import cn.kgc.ssm.mapper.LogsMapper;
import cn.kgc.ssm.service.LogsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/5/20
 * @description
 */
@Service
public class LogsServiceImpl implements LogsService {

    @Resource
    private LogsMapper logsMapper;

    @Override
    public ResponseResult addLogInfo(LogInfo logInfo) {

        logsMapper.addLogInfo(logInfo);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult logsPage(Integer page, Integer limit, String model, String description) {

        PageHelper.startPage(page,limit);

        List<LogInfo>  logInfos =  logsMapper.searchLogs(model,description);
        PageInfo<LogInfo> logInfoPageInfo = new PageInfo<>(logInfos);
        long total = logInfoPageInfo.getTotal();

        return ResponseResult.success().data(logInfos).count(total);
    }

    @Override
    public ResponseResult deleteLogs(Integer[] ids) {

        logsMapper.deleteLogs(ids);

        return ResponseResult.success().message("删除成功");
    }
}
